package jsyf.oa.service.wechat.service_company;

import java.io.*;
import java.util.List;

/**
 * Created by jjx on 2018/4/1.
 */
public class ContactsSynchronizeFile {
    /**
     * 描述:  创建CSV文件
     *
     * @param messages (正文信息)list,存放文件
     * @param fileName 临时文件名称
     * @return File
     */
    public static File send(List<String> messages, String fileName) {
        File csvFile = null;
        BufferedWriter csvFileOutputStream = null;
        try {
            // 定义文件名格式并创建
            csvFile = File.createTempFile(fileName, ".csv");
            // UTF-8使正确读取分隔符","
            csvFileOutputStream = new BufferedWriter(
                    new OutputStreamWriter(
                            new FileOutputStream(csvFile), "UTF-8"), 1024);
            for (String s : messages) {
                csvFileOutputStream.write(s);
                csvFileOutputStream.newLine();
            }
            csvFileOutputStream.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                csvFileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return csvFile;
    }

}
